require 'compass/import-once/activate'

sass_dir = "media/tea/sass"
sass_path = File.expand_path(sass_dir)
# sass_path = File.expand_path("..", __FILE__)

images_dir = 'images'

cache = false #sass缓存
sourcemap = false #浏览器调试
output_style = :expanded #输出样式
relative_assets = false #相对路径
line_comments = true #注释

on_sprite_saved do |filename|
  if File.exists?(filename)
    #FileUtils.mv filename, filename.gsub(%r{-s[a-z0-9]{10}\.png$}, '.png')
    #使用mv删除图片会使每次修改时都会重新生成图片.所以不建议使用
    FileUtils.cp filename, filename.gsub(%r{-s[a-z0-9]{10}\.png$}, '.png')
  end
end

# Replace in stylesheets generated references to sprites
# by their counterparts without the hash uniqueness.
on_stylesheet_saved do |filename|
  if File.exists?(filename)
    css = File.read(filename, :encoding=>"utf-8")
    #File.read_with_options(file, :encoding=>"utf-8")
    File.open(filename, 'w+') do |f|
      f << css.gsub(%r{-s([a-z0-9]{10})\.png}, '.png?v=\1')
    end
  end
end

